
	
	/**
	 * 评论
	 * @param formId
	 */
	function reply(formId){		
		var vo = $("#" + formId).serialize();
	    var url = cxt + '/portal/demo/reply';
	    	
	    //前端js校验
	    if ($("#" + formId + " #message").val() == '') {
    		layer.msg('回复不能为空');
    		return false;
    	}
	 	
	    $.ajax({
	    	type:'post',
	   		url:url,
	   		data:vo,	
	   		cache:false,
	   		async:true,
	   		success:function(json){
	   			layer.msg(json.data);
	   			//layer.alert(json.info);
	   			$("#tbody").empty(); 
	   			getDemoComment();
	   		},
	   	    error:function(){
	   	    	layer.msg("执行错误！", 8);
	   	    }
	   	});
		
	}
	
	function openPayview(demoId){
		
		var url = '../isLogin';
		//轮询是否已经付费
		$.ajax({
	    	type:'post',
	   		url:url,
	   		cache:false,
	   		async:true,
	   		success:function(json){
	   			if(json.result == 0){
	   				layer.open({
	   		            type: 1,
	   		            closeBtn: true,
	   		            title: false,
	   		            shift: 2,
	   		            shadeClose: true,
	   		            content: $("#pay")
	   		        });
	   				
	   				//是否促销
	   				url = cxt + '/portal/demo/isChangePrice';
	   			    $.ajax({
	   			    	type:'post',
	   			   		url:url,
	   			   		data:{demoId:demoId},
	   			   		cache:false,
	   			   		async:true,
	   			   		success:function(json){
	   			   			//layer.msg(json.data);
	   			   			if(json.data != 'NO_DISCOUNT'){
	   			   				$("#DEMO_PRICE").html(json.data);
	   			   			}
	   			   		},
	   			   	    error:function(){
	   			   	    	//layer.msg("执行错误！", 8);
	   			   	    }
	   			   	});
	   			    
	   			} else {
	   				layer.open({
	   					area: ['600px', '320px'],
	   		            type: 2,
	   		            closeBtn: true,
	   		            title: false,
	   		            shift: 2,
	   		            shadeClose: true,
	   		            content:'../openLoginDialog'
	   		        });
	   			}
	   			
	   		},
	   	    error:function(){
	   	    	layer.msg("执行错误！", 8);
	   	    }
	   	});
		
	}
	
	/**
	 * 购买demo
	 */
	function buydemo(demoId){
		//打开付费二维码 -- 微信二维码
		layer.open({
			area: ['300px', '300px'],
            type: 2,
            closeBtn: false,
            title: false,
            shift: 2,
            shadeClose: true,
            content:'../pay/weixin/qrcode?demoId=' + demoId
        });
		
		//重复执行某个方法 
		var t1 = window.setInterval("getPayState(" + demoId + ")",1500); 
	}
	
	/**
	 * 免费
	 */
	function freebuydemo(demoId){
		var url = cxt + '/portal/demo/buyDemo';
	    $.ajax({
	    	type:'post',
	   		url:url,
	   		data:{demoId:demoId},
	   		cache:false,
	   		async:true,
	   		success:function(json){
	   			layer.msg(json.data);
		   		setTimeout(function () {
		   			if(json.result == 0)
		   				window.open(cxt + '/mydemo/buy.html');
		   			window.location.reload();
		   		}, 2000);
	   			
	   		},
	   	    error:function(){
	   	    	layer.msg("执行错误！", 8);
	   	    }
	   	});
	}
	
	/**
	 * 打赏
	 * @param demoId
	 */
	function buydemo4reward(demoId){
		freebuydemo(demoId);
	}
	
	/**
	 *  购买demo
	 * @param payType1  付款前后的类型
	 * @returns
	 */
	/*function buydemo(payType1){
		
		if(payType1 == '1')
			layer('2','../qrcode.do');*/
		
	    /*var url = cxt + '/portal/demo/buyDemo';
	    var demoId = $("#_demo_Id").val();
	    	    
	    $.ajax({
	    	type:'post',
	   		url:url,
	   		data:{demoId:demoId},
	   		cache:false,
	   		async:true,
	   		success:function(json){
	   			layer.msg(json.data);
		   		setTimeout(function () {
		   			if(json.result == 0)
		   				window.open(cxt + '/mydemo/buy.html');
		   			window.location.reload();
		   		}, 2000);
	   			
	   		},
	   	    error:function(){
	   	    	layer.msg("执行错误！", 8);
	   	    }
	   	});*/
	//}
	
	/**
	 * 收藏demo
	 * @param formId
	 */
	function collectdemo(){		
	    var url = cxt + '/portal/demo/collectDemo';
	    var demoId = $("#_demo_Id").val();
	    $.ajax({
	    	type:'post',
	   		url:url,
	   		data:{demoId:demoId},
	   		cache:false,
	   		async:true,
	   		success:function(json){
	   			layer.msg(json.data);
	   		},
	   	    error:function(){
	   	    	layer.msg("执行错误！", 8);
	   	    }
	   	});
	}
	
	/**
	 * 
	 * @param divId
	 */
	function showReplyDIV(divId){
		var divId = '#' + divId;
		if($(divId).css("display") == "none")
			$(divId).css("display","block");
		else
			$(divId).css("display","none");
	}
	
    /**
     * 获得dmeo分页列表
     */
    function getDemoComment(){
    	var url = cxt + '/portal/demo/getDemoComment4page';
    	var demoId = $("#_demo_Id").val();
    	var pageSize = 4;
    	$.ajax({
			url : url,
			data:{demoId:demoId, pageSize:pageSize, pageNumber:1},
			type:'post',
			async : true,
			success : function(json) {
				var pageCount = json.totalPage;
				$("#commentTitle").text(json.totalCount + "个评论");
				//------------------------------
		    	laypage({
		    	    cont: 'biuuu_city', //容器。值支持id名、原生dom对象，jquery对象,
		    	    pages: pageCount, //总页数
		    	    groups: 0, //连续分数数0
		    	    prev: false, //不显示上一页
		    	    next: '查看更多',
		    	    skin: 'flow', //设置信息流模式的样式
		    	    jump: function(obj){
		    	        if(obj.curr === pageCount -1){
		    	            this.next = '没有更多了';
		    	        }
		    	        
		    	        $.ajax({
		        			url : url,
		        			data:{demoId:demoId, pageSize:pageSize, pageNumber:obj.curr},
		        			type:'post',
		        			async : true,
		        			success : function(json) {
		        				if(json.result == "0"){
		        					var data = json.data;
		        					//解析数据
		        					if(null!=data){
		        						$('#tbody').append($("#trTmpl").render(data));
		        					}
		        			    }
		        			}
		        		});
		    			
		    	    }
		    	});
		    	//------------------------------
			}
		});
    	
    }
    
    
    /**
	 * 获得某个demo是否被某个用户收藏或者购买了
	 * @param formId
	 */
	function getIsBuyAndIsfavo(){		
	    var url = cxt + '/portal/getIsBuyAndIsfavo';
	    var demoId = $("#_demo_Id").val();
	    $.ajax({
	    	type:'post',
	   		url:url,
	   		data:{demoId:demoId},
	   		cache:false,
	   		async:true,
	   		success:function(json){
	   			layer.msg(json.data);
	   			if(json.isbuy == true){
	   				alert(json.isbuy);
	   			}
	   			if(json.isfavo == true){
	   				alert(json.isfavo);
	   			}
	   		},
	   	    error:function(){
	   	    	//layer.msg("执行错误！", 8);
	   	    }
	   	});
	}
	
    $(function(){
    	getDemoComment();
    	SyntaxHighlighter.all();
    	
    	$("#queryAll").click(function(){
    		$("#mainForm #toPage").val("0");
    		geUserList();
    	});
    	$(".varclose,#return,#closeView").click(function(){
        	layer.closeAll();
        });
    	
       
        
        if($("#editorType").val() == "M") {
        	 var  testEditormdView2;
        	 testEditormdView2 = editormd.markdownToHTML("demodashi-editormd-view", {
	            //htmlDecode      : true,       // 开启 HTML 标签解析，为了安全性，默认不开启
	            htmlDecode      : "style,script,iframe",  // you can filter tags decode
	            //toc             : false,
	            tocm            : true,    // Using [TOCM]
	            //tocContainer    : "#custom-toc-container", // 自定义 ToC 容器层
	            //gfm             : false,
	            //tocDropdown     : true,
	            // markdownSourceCode : true, // 是否保留 Markdown 源码，即是否删除保存源码的 Textarea 标签
	            emoji           : true,
	            taskList        : true,
	            tex             : true,  // 默认不解析
	            flowChart       : true,  // 默认不解析
	            sequenceDiagram : true,  // 默认不解析
	
	        });
        }
        
    	$('#yuyue').on('click', function(){
    		layer.open({
    			area: ['360px', '330px'],
                type: 1,
                closeBtn: true,
                title: false,
                shift: 2,
                shadeClose: true,
                content: $("#service")
            });
    		
    		 /* layer.tips('马上就开通啦，等等呢', this, {
    		    style: ['background-color:#0FA6D8; color:#fff', '#0FA6D8'],
    		    maxWidth:150
    		  });*/
    		});
    	
    });
    
   
	
